package com.example.bausip;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class AssistantsActivity extends Activity {

	ArrayList<NameEntity> assistants;
	ArrayList<Item> assistantItems;
	MyCustomAdapter dataAdapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_majors);
		setassistants("","");
	}

	public void setassistants(String s, String error) {
		Log.d("ray", "reply: " + s);
		NameEntity ne = null;
		assistants = new ArrayList<NameEntity>();
		for (int i = 0; i < 10; i++) {
			ne = new NameEntity(i, "assistants " + i, "assistant");
			assistants.add(ne);
		}
		assistantItems = new ArrayList<Item>();
		ListView listView = (ListView) findViewById(R.id.list);

		listView.setTextFilterEnabled(true);
		if (assistants.size() == 0) {
			assistantItems.add(new Item(0, "", getString(R.string.empty_list)));
		} else {
			for (int i = 1; i < assistants.size(); i++) {
				assistantItems.add(new Item(assistants.get(i).getId(), "",
						assistants.get(i).toString()));
			}
			registerForContextMenu(listView);
			dataAdapter = new MyCustomAdapter(this, R.layout.name_list,
					assistantItems);
			SharedMenu.adapter = dataAdapter;
			listView.setAdapter(dataAdapter);
			listView.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {
					if (dataAdapter.tmpList.size() > 0) {
						Intent i;
						i = new Intent(getBaseContext(),AddStudentActivity.class);
						startActivity(i);

					}
				}
			});
		}
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.instructors , menu);
		SharedMenu.onCreateOptionsMenu(this, menu, getApplicationContext(),
				dataAdapter);
		return true;

	}
	public boolean onOptionsItemSelected(MenuItem item) {

		if (SharedMenu.onOptionsItemSelected(item, this) == false) {
			// handle local menu items here or leave blank

			switch (item.getItemId()) {
			case R.id.add:
				Intent intent = new Intent(this, AddStudentActivity.class);
				startActivity(intent);
				break;
			}
		}
		return super.onOptionsItemSelected(item);
	}

}
